import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    meta: {
      title: '走心的社交语音平台'
    }
  },
  {
    path: '/detailShow',
    name: 'detail',
    component: () => import('../views/DetailView.vue'),
    meta: {
      title: '详情展示'
    }
  },
  {
    path: '/aboutUs',
    name: 'about',
    component: () => import('../views/AboutView.vue'),
    meta: {
      title: '关于我们'
    }
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  console.log(to.meta)
  if (to.meta.title) { //拦截后设置标题
    document.title = `${to.meta.title}-蜜蜂语音`
  }
  next()
})

export default router
